package ModelAndView

type ModelAndView struct {
	Viewname string
	Attribute map[string]interface{}
	RequestAttribute map[string]interface{}
	SessionAttribute map[string]interface{}
}

func CreateModelAndView(viewname string, attribute map[string]interface{})(ModelAndView){
	return ModelAndView{Viewname:viewname,Attribute:attribute}
}
func (m ModelAndView)SetAttribute(key string, value interface{}){
	if(m.Attribute==nil){
		m.Attribute = make(map[string]interface{})
	}
	m.Attribute[key]=value
}
func (m ModelAndView)RemoveAttribute(key string){
	if(m.Attribute==nil){
		m.Attribute = make(map[string]interface{})
	}
	delete(m.Attribute,key)
}

func (m ModelAndView)AddRequestAttribute(key string,value interface{}){
	m.RequestAttribute[key]=value
}

func (m ModelAndView)AddSessionAttribute(key string,value interface{}){
	m.SessionAttribute[key]=value
}

func (m ModelAndView)GetObject(key string)interface{}{
	if _,ok := m.Attribute[key]; ok {
		return m.Attribute[key]
	}
	if _,ok := m.RequestAttribute[key]; ok {
		return m.RequestAttribute[key]
	}
	if _,ok := m.SessionAttribute[key]; ok {
		return m.SessionAttribute[key]
	}
	return nil
}
